package com.ymatou.iapi.userservice.testcase;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ImgAndFileCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
import com.ymatou.iapi.userservice.parameter.req.*;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ymatou.iapi.userservice.parameter.enums.*;
import com.ymatou.iapi.userservice.service.*;

/**
 * 查询头像Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GUserLogoRequestDto {
	private static QueryUserLogoRequestNetReq QueryUserLogoRequestNetReq;
	private static GUserLogoRequestDtoCall GUserLogoRequestDtoCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询头像");
	}

	@Before
	public void caseUp() {
		QueryUserLogoRequestNetReq = new QueryUserLogoRequestNetReq();
		GUserLogoRequestDtoCall = new GUserLogoRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(GUserLogoRequestDtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_001() {
		Logger.start(true, "查询头像,成功");
		try {
			Map<Integer, String> m = new HashMap<>();

			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
			SetUserLogoBean.setUserId(uid);
			SetUserLogoBean.setLogoUrl("http://www.ymatou.com/testimg.jpg");
			m.put(uid, SetUserLogoBean.getLogoUrl());
			JUserCallService.SetUserLogoCall(SetUserLogoBean);
			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.SearchList);
			String userIds = uid.toString();
			QueryUserLogoRequestNetReq.setUserIds(userIds);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("true", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonArray ja = GUserLogoRequestDtoCall.getJsonObject().get("Result").getAsJsonArray();
			for (JsonElement jsonElement : ja) {
				int tuid = jsonElement.getAsJsonObject().get("iUserId").getAsInt();
				Logger.verifyEquals(m.get(tuid), jsonElement.getAsJsonObject().get("sLogoUrl").getAsString(), "验证sLogoUrl");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_002() {
		Logger.start(true, "查询多个头像,成功");
		try {
			String userIds = "";
			Map<Integer, String> m = new HashMap<>();
			for (int i = 0; i < 3; i++) {
				CreateUserReq cur = new CreateUserReq();
				cur = JUserCallService.initCreateUserBean(cur);
				cur.setMail(null);
				Integer uid = JUserCallService.createUserCall(cur);
				SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
				SetUserLogoBean.setUserId(uid);
				SetUserLogoBean.setLogoUrl("http://www.ymatou.com/testimg.jpg");
				JUserCallService.SetUserLogoCall(SetUserLogoBean);
				m.put(uid, SetUserLogoBean.getLogoUrl());
				userIds += uid.toString() + ",";
			}

			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.SearchList);

			QueryUserLogoRequestNetReq.setUserIds(userIds);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("true", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonArray ja = GUserLogoRequestDtoCall.getJsonObject().get("Result").getAsJsonArray();
			for (JsonElement jsonElement : ja) {
				int tuid = jsonElement.getAsJsonObject().get("iUserId").getAsInt();
				Logger.verifyEquals(m.get(tuid), jsonElement.getAsJsonObject().get("sLogoUrl").getAsString(), "验证sLogoUrl");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_003() {
		Logger.start(false, "不输入userids,失败");
		try {
			Map<Integer, String> m = new HashMap<>();

			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
			SetUserLogoBean.setUserId(uid);
			SetUserLogoBean.setLogoUrl("http://www.ymatou.com/testimg.jpg");
			m.put(uid, SetUserLogoBean.getLogoUrl());
			JUserCallService.SetUserLogoCall(SetUserLogoBean);
			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.SearchList);
			String userIds = uid.toString();
			// QueryUserLogoRequestNetReq.setUserIds(userIds);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("false", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_004() {
		Logger.start(true, "查询多个头像到数量上限,成功");
		try {
			String userIds = "";
			Map<Integer, String> m = new HashMap<>();
			// 现在配置是5个 ？ 待确认
			for (int i = 0; i < 5; i++) {
				CreateUserReq cur = new CreateUserReq();
				cur = JUserCallService.initCreateUserBean(cur);
				cur.setMail(null);
				Integer uid = JUserCallService.createUserCall(cur);
				SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
				SetUserLogoBean.setUserId(uid);
				SetUserLogoBean.setLogoUrl("http://www.ymatou.com/testimg.jpg");
				JUserCallService.SetUserLogoCall(SetUserLogoBean);
				m.put(uid, SetUserLogoBean.getLogoUrl());
				userIds += uid.toString() + ",";
			}

			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.SearchList);

			QueryUserLogoRequestNetReq.setUserIds(userIds);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("true", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonArray ja = GUserLogoRequestDtoCall.getJsonObject().get("Result").getAsJsonArray();
			for (JsonElement jsonElement : ja) {
				int tuid = jsonElement.getAsJsonObject().get("iUserId").getAsInt();
				Logger.verifyEquals(m.get(tuid), jsonElement.getAsJsonObject().get("sLogoUrl").getAsString(), "验证sLogoUrl");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_005() {
		Logger.start(false, "查询多个头像超限,失败");
		try {
			String userIds = "";
			Map<Integer, String> m = new HashMap<>();
			for (int i = 0; i <= 100; i++) {
				userIds += i + ",";
			}
			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.SearchList);
			QueryUserLogoRequestNetReq.setUserIds(userIds);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("false", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200006", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_006() {
		Logger.start(true, "批量查询头像指定类型Original,成功");
		try {
			String fliename = System.getProperty("user.dir") + File.separator + "resource" + File.separator + "Penguins.jpg";
			String type = "userlogo";
			String img = ImgAndFileCallService.uploadImg(fliename, type, null);
			Map<Integer, String> m = new HashMap<>();

			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
			SetUserLogoBean.setUserId(uid);
			SetUserLogoBean.setLogoUrl(img);
			m.put(uid, SetUserLogoBean.getLogoUrl());
			JUserCallService.SetUserLogoCall(SetUserLogoBean);
			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.SearchList);
			String userIds = uid.toString();
			QueryUserLogoRequestNetReq.setUserIds(userIds);
			QueryUserLogoRequestNetReq.setLogoType(UserLogoTypeEnum.Original);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("true", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonArray ja = GUserLogoRequestDtoCall.getJsonObject().get("Result").getAsJsonArray();
			for (JsonElement jsonElement : ja) {
				int tuid = jsonElement.getAsJsonObject().get("iUserId").getAsInt();
				Logger.verifyEquals(m.get(tuid), jsonElement.getAsJsonObject().get("sLogoUrl").getAsString(), "验证sLogoUrl");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_007() {
		Logger.start(true, "查询头像指定类型Original,成功");
		try {
			String fliename = System.getProperty("user.dir") + File.separator + "resource" + File.separator + "Penguins.jpg";
			String type = "userlogo";
			String img = ImgAndFileCallService.uploadImg(fliename, type, null);
			Map<Integer, String> m = new HashMap<>();

			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
			SetUserLogoBean.setUserId(uid);
			SetUserLogoBean.setLogoUrl(img);
			m.put(uid, SetUserLogoBean.getLogoUrl());
			JUserCallService.SetUserLogoCall(SetUserLogoBean);
			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.Search);
			String userIds = uid.toString();
			QueryUserLogoRequestNetReq.setUserIds(userIds);
			QueryUserLogoRequestNetReq.setLogoType(UserLogoTypeEnum.Original);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("true", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject ja = GUserLogoRequestDtoCall.getJsonObject().getAsJsonObject("Result");
			int tuid = ja.getAsJsonObject().get("iUserId").getAsInt();
			Logger.verifyEquals(m.get(tuid), ja.getAsJsonObject().get("sLogoUrl").getAsString(), "验证sLogoUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_008() {
		Logger.start(true, "查询头像指定类型Middle,成功");
		try {
			String fliename = System.getProperty("user.dir") + File.separator + "resource" + File.separator + "Penguins.jpg";
			String type = "userlogo";
			String img = ImgAndFileCallService.uploadImg(fliename, type, null);
			Map<Integer, String> m = new HashMap<>();

			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
			SetUserLogoBean.setUserId(uid);
			SetUserLogoBean.setLogoUrl(img);
			m.put(uid, SetUserLogoBean.getLogoUrl());
			JUserCallService.SetUserLogoCall(SetUserLogoBean);
			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.Search);
			String userIds = uid.toString();
			QueryUserLogoRequestNetReq.setUserIds(userIds);
			QueryUserLogoRequestNetReq.setLogoType(UserLogoTypeEnum.Middle);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("true", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject ja = GUserLogoRequestDtoCall.getJsonObject().getAsJsonObject("Result");
			int tuid = ja.getAsJsonObject().get("iUserId").getAsInt();
			Logger.verifyEquals(ImgAndFileCallService.changeUrl(m.get(tuid), "_m"), ja.getAsJsonObject().get("sLogoUrl").getAsString(), "验证sLogoUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_009() {
		Logger.start(true, "查询头像指定类型Small,成功");
		try {
			String fliename = System.getProperty("user.dir") + File.separator + "resource" + File.separator + "Penguins.jpg";
			String type = "userlogo";
			String img = ImgAndFileCallService.uploadImg(fliename, type, null);
			Map<Integer, String> m = new HashMap<>();

			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
			SetUserLogoBean.setUserId(uid);
			SetUserLogoBean.setLogoUrl(img);
			m.put(uid, SetUserLogoBean.getLogoUrl());
			JUserCallService.SetUserLogoCall(SetUserLogoBean);
			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.Search);
			String userIds = uid.toString();
			QueryUserLogoRequestNetReq.setUserIds(userIds);
			QueryUserLogoRequestNetReq.setLogoType(UserLogoTypeEnum.Small);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("true", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject ja = GUserLogoRequestDtoCall.getJsonObject().getAsJsonObject("Result");
			int tuid = ja.getAsJsonObject().get("iUserId").getAsInt();
			Logger.verifyEquals(ImgAndFileCallService.changeUrl(m.get(tuid), "_s"), ja.getAsJsonObject().get("sLogoUrl").getAsString(), "验证sLogoUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GUserLogoRequestDto_010() {
		Logger.start(true, "批量查询头像指定类型Middle,成功");
		try {
			String fliename = System.getProperty("user.dir") + File.separator + "resource" + File.separator + "Penguins.jpg";
			String type = "userlogo";
			String img = ImgAndFileCallService.uploadImg(fliename, type, null);
			Map<Integer, String> m = new HashMap<>();

			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
			SetUserLogoBean.setUserId(uid);
			SetUserLogoBean.setLogoUrl(img);
			m.put(uid, SetUserLogoBean.getLogoUrl());
			JUserCallService.SetUserLogoCall(SetUserLogoBean);
			QueryUserLogoRequestNetReq.setLogoOperatingEnum(UserLogoActionEnum.SearchList);
			String userIds = uid.toString();
			QueryUserLogoRequestNetReq.setUserIds(userIds);
			QueryUserLogoRequestNetReq.setLogoType(UserLogoTypeEnum.Middle);
			GUserLogoRequestDtoCall.setData(QueryUserLogoRequestNetReq);
			GUserLogoRequestDtoCall.callService();
			Logger.verifyEquals("true", GUserLogoRequestDtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", GUserLogoRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonArray ja = GUserLogoRequestDtoCall.getJsonObject().get("Result").getAsJsonArray();
			for (JsonElement jsonElement : ja) {
				int tuid = jsonElement.getAsJsonObject().get("iUserId").getAsInt();
				Logger.verifyEquals(ImgAndFileCallService.changeUrl(m.get(tuid), "_m"), jsonElement.getAsJsonObject().get("sLogoUrl").getAsString(), "验证sLogoUrl");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}